package com.ease.integration.definition.service.impl;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ease.common.util.Detect;
import com.ease.integration.definition.service.IntegrationServiceDefinitionManagementService;
import com.ease.integration.definition.vo.IntegrationServiceDefinition;

public class IntegrationServiceDefinitionManagementServiceImpl extends Detect implements IntegrationServiceDefinitionManagementService {

	private List<IntegrationServiceDefinition> integrationServiceDefinitions;

	private Map<String, IntegrationServiceDefinition> integrationServiceDefinitionMap = null;

	public void init() {
		if (notEmpty(integrationServiceDefinitions)) {
			Map<String, IntegrationServiceDefinition> maps = new HashMap<String, IntegrationServiceDefinition>();
			for (IntegrationServiceDefinition integrationServiceDefinition : integrationServiceDefinitions) {
				maps.put(integrationServiceDefinition.getKey(), integrationServiceDefinition);
			}
			integrationServiceDefinitionMap = Collections.unmodifiableMap(maps);
		}
	}

	public IntegrationServiceDefinition getIntegrationServiceDefinitionByKey(String key) {
		if (null != integrationServiceDefinitionMap) {
			return integrationServiceDefinitionMap.get(key);
		}
		return null;
	}

	/**
	 * @return the integrationServiceDefinitions
	 */
	public List<IntegrationServiceDefinition> getIntegrationServiceDefinitions() {
		return integrationServiceDefinitions;
	}

	/**
	 * @param integrationServiceDefinitions
	 *            the integrationServiceDefinitions to set
	 */
	public void setIntegrationServiceDefinitions(List<IntegrationServiceDefinition> integrationServiceDefinitions) {
		this.integrationServiceDefinitions = integrationServiceDefinitions;
	}

}
